package com.linx.lounge.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.linx.common.idempotent.annotation.RepeatSubmit;
import com.linx.common.log.annotation.Log;
import com.linx.common.web.core.BaseController;
import com.linx.common.mybatis.core.page.PageQuery;
import com.linx.common.core.domain.R;
import com.linx.common.core.validate.AddGroup;
import com.linx.common.core.validate.EditGroup;
import com.linx.common.log.enums.BusinessType;
import com.linx.common.excel.utils.ExcelUtil;
import com.linx.lounge.domain.vo.LoungeFacilityVo;
import com.linx.lounge.domain.bo.LoungeFacilityBo;
import com.linx.lounge.service.ILoungeFacilityService;
import com.linx.common.mybatis.core.page.TableDataInfo;

/**
 * 休息室-设施
 *
 * @author linx
 * @date 2024-10-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/lounge/lounge-facility")
public class LoungeFacilityController extends BaseController {

    private final ILoungeFacilityService loungeFacilityService;

    /**
     * 查询休息室-设施列表
     */
    @SaCheckPermission("lounge:lounge-facility:list")
    @GetMapping("/list")
    public TableDataInfo<LoungeFacilityVo> list(LoungeFacilityBo bo, PageQuery pageQuery) {
        return loungeFacilityService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出休息室-设施列表
     */
    @SaCheckPermission("lounge:lounge-facility:export")
    @Log(title = "休息室-设施", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(LoungeFacilityBo bo, HttpServletResponse response) {
        List<LoungeFacilityVo> list = loungeFacilityService.queryList(bo);
        ExcelUtil.exportExcel(list, "休息室-设施", LoungeFacilityVo.class, response);
    }

    /**
     * 获取休息室-设施详细信息
     *
     * @param loungeFacilityId 主键
     */
    @SaCheckPermission("lounge:lounge-facility:query")
    @GetMapping("/{loungeFacilityId}")
    public R<LoungeFacilityVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long loungeFacilityId) {
        return R.ok(loungeFacilityService.queryById(loungeFacilityId));
    }

    /**
     * 新增休息室-设施
     */
    @SaCheckPermission("lounge:lounge-facility:add")
    @Log(title = "休息室-设施", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody LoungeFacilityBo bo) {
        return toAjax(loungeFacilityService.insertByBo(bo));
    }

    /**
     * 修改休息室-设施
     */
    @SaCheckPermission("lounge:lounge-facility:edit")
    @Log(title = "休息室-设施", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody LoungeFacilityBo bo) {
        return toAjax(loungeFacilityService.updateByBo(bo));
    }

    /**
     * 删除休息室-设施
     *
     * @param loungeFacilityIds 主键串
     */
    @SaCheckPermission("lounge:lounge-facility:remove")
    @Log(title = "休息室-设施", businessType = BusinessType.DELETE)
    @DeleteMapping("/{loungeFacilityIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] loungeFacilityIds) {
        return toAjax(loungeFacilityService.deleteWithValidByIds(List.of(loungeFacilityIds), true));
    }
}
